﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;
using System.Text.RegularExpressions;

namespace XamlCast.Player.Utils {
    public static class StringUtil {

        #region RemoveDiacritics (Acentos)
        /// <summary>
        /// Remove os caracteres acentuados de um texto, substituindo pelo caracter sem acento.
        /// </summary>
        /// <remarks>Remove os caracteres acentuados de um texto, substituindo pelo caracter sem acento.</remarks>
        /// <param name="texto">Texto cujos caracteres acentuados serão removidos.</param>
        /// <returns>Texto sem os caracteres acentuados.</returns>
        public static string RemoveDiacritics(this string texto) {
            string result = string.Empty;

            if (!string.IsNullOrEmpty(texto)) {
                result = texto.RegexReplace(@"á|ã|â|à|ä", "a").RegexReplace(
                    @"Á|Ã|Â|À|Ä", "A").RegexReplace(
                    @"é|ê|è|ë", "e").RegexReplace(
                    @"É|Ê|È|Ë", "E").RegexReplace(
                    @"í|î|ì|ï", "i").RegexReplace(
                    @"Í|Î|Ì|Ï", "I").RegexReplace(
                    @"ó|õ|ô|ò|ö", "o").RegexReplace(
                    @"Ó|Õ|Ô|Ò|Ö", "O").RegexReplace(
                    @"ú|û|ù|ü", "u").RegexReplace(
                    @"Ú|Û|Ù|Ü", "U").RegexReplace(
                    @"ñ", "n").RegexReplace(@"Ñ", "N").RegexReplace(
                    @"ç", "c").RegexReplace(@"Ç", "C");
            }

            return result;
        }
        #endregion

        public static string RegexReplace(this string input, string pattern, string replacement) {
            return Regex.Replace(input, pattern, replacement);
        }

    }
}
